package com.grass.p019lv.game;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.GridLayoutManager;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.APPLink;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.AdInfoBean;
import com.androidx.p013lv.base.bean.GameAccountBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.service.AdClickService;
import com.androidx.p013lv.base.utils.AdUtils;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.invention.adapter.MyBannerAdapter;
import com.grass.p019lv.databinding.FragmentGameBinding;
import com.grass.p019lv.game.adapter.GameAdapter;
import com.grass.p019lv.game.bean.GameBean;
import com.grass.p019lv.game.bean.GameUrlBean;
import com.grass.p019lv.game.view.LoadingDialog;
import com.gyf.immersionbar.ImmersionBar;
import com.youth.banner.indicator.RectangleIndicator;
import com.youth.banner.listener.OnBannerListener;
import java.util.ArrayList;
import java.util.List;

/* renamed from: com.grass.lv.game.GameFragment */
public class GameFragment extends LazyFragment<FragmentGameBinding> {
    GameAdapter adapter;
    APPLink appLink;
    private LoadingDialog loadingDialog;

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_game;
    }

    public static GameFragment newInstance() {
        Bundle bundle = new Bundle();
        GameFragment gameFragment = new GameFragment();
        gameFragment.setArguments(bundle);
        return gameFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment, com.gyf.immersionbar.components.ImmersionOwner
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(getActivity()).titleBar(((FragmentGameBinding) this.binding).toolbar).init();
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        this.loadingDialog = LoadingDialog.newInstance();
        ((FragmentGameBinding) this.binding).setClick(new OnClick());
        List<AdInfoBean> adSort = AdUtils.getInstance().getAdSort(Constance.AD_GAME_PAGE);
        if (adSort == null || adSort.size() <= 0) {
            ((FragmentGameBinding) this.binding).banner.setVisibility(8);
        } else {
            ((FragmentGameBinding) this.binding).banner.setVisibility(0);
            setBanner(adSort);
        }
        this.adapter = new GameAdapter();
        ((FragmentGameBinding) this.binding).recycler.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        ((FragmentGameBinding) this.binding).recycler.setAdapter(this.adapter);
        ArrayList arrayList = new ArrayList();
        arrayList.add(new GameBean(2, "斗地主", R.drawable.ic_game2));
        arrayList.add(new GameBean(5, "抢庄牛牛", R.drawable.ic_game5));
        arrayList.add(new GameBean(14, "视讯百家乐", R.drawable.ic_game14));
        arrayList.add(new GameBean(26, "抢庄三公", R.drawable.ic_game26));
        arrayList.add(new GameBean(29, "抢庄二八杠", R.drawable.ic_game29));
        arrayList.add(new GameBean(1, "捕鱼", R.drawable.ic_game1));
        arrayList.add(new GameBean(4, "百人牛牛", R.drawable.ic_game4));
        arrayList.add(new GameBean(28, "抢庄牌九", R.drawable.ic_game28));
        arrayList.add(new GameBean(12, "龙虎大战", R.drawable.ic_game12));
        arrayList.add(new GameBean(7, "红黑大战", R.drawable.ic_game7));
        arrayList.add(new GameBean(19, "飞禽走兽", R.drawable.ic_game19));
        arrayList.add(new GameBean(18, "奔驰宝马", R.drawable.ic_game18));
        arrayList.add(new GameBean(27, "看三张抢庄牛牛", R.drawable.ic_game27));
        arrayList.add(new GameBean(25, "21点", R.drawable.ic_game25));
        arrayList.add(new GameBean(3, "炸金花", R.drawable.ic_game3));
        arrayList.add(new GameBean(6, "二人麻将", R.drawable.ic_game6));
        arrayList.add(new GameBean(10, "跑得快", R.drawable.ic_game10));
        this.adapter.setData(arrayList);
        this.adapter.setItemListener(new ItemClickListener() {
            /* class com.grass.p019lv.game.GameFragment.C30151 */

            @Override // com.androidx.p013lv.base.listener.ItemClickListener
            public void onItemClick(View view, int i) {
                if (!GameFragment.this.isOnClick()) {
                    GameFragment.this.getGameUrl(((GameBean) GameFragment.this.adapter.getDataInPosition(i)).getGameNo());
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getGameUrl(int i) {
        this.loadingDialog.show(getFragmentManager(), "loadingDialog");
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getGameUrl(i), new HttpCallback<BaseRes<GameUrlBean>>("getGameUrl") {
            /* class com.grass.p019lv.game.GameFragment.C30162 */

            public void onLvSuccess(BaseRes<GameUrlBean> baseRes) {
                if (GameFragment.this.binding != null) {
                    if (GameFragment.this.loadingDialog != null) {
                        GameFragment.this.loadingDialog.dismiss();
                    }
                    if (200 == baseRes.getCode()) {
                        GameUrlBean data = baseRes.getData();
                        if (!TextUtils.isEmpty(data.getGameUrl())) {
                            Intent intent = new Intent(GameFragment.this.getActivity(), GameWebViewActivity.class);
                            intent.putExtra(Key.WEB_VIEW_URL, data.getGameUrl());
                            GameFragment.this.startActivity(intent);
                            return;
                        }
                        ToastUtils.getInstance().showWeak(data.getGameReason());
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            }
        });
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onResume() {
        super.onResume();
        getGameAccount();
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        super.onDestroy();
        if (this.loadingDialog != null) {
            this.loadingDialog = null;
        }
        HttpUtils.getInsatance().cancelTag("getGameAccount");
        HttpUtils.getInsatance().cancelTag("getGameUrl");
    }

    private void getGameAccount() {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getGameAccount(), new HttpCallback<BaseRes<GameAccountBean>>("getGameAccount") {
            /* class com.grass.p019lv.game.GameFragment.C30173 */

            public void onLvSuccess(BaseRes<GameAccountBean> baseRes) {
                if (GameFragment.this.binding != null && 200 == baseRes.getCode()) {
                    GameAccountBean data = baseRes.getData();
                    TextView textView = ((FragmentGameBinding) GameFragment.this.binding).tvGameMoney;
                    textView.setText(data.getGameBalance() + "");
                    TextView textView2 = ((FragmentGameBinding) GameFragment.this.binding).tvMoney;
                    textView2.setText(data.getBalance() + "");
                    SpUtils.getInstance().setUserGameAccount(data);
                }
            }
        });
    }

    public void setBanner(List<AdInfoBean> list) {
        ViewGroup.LayoutParams layoutParams = ((FragmentGameBinding) this.binding).banner.getLayoutParams();
        layoutParams.height = UiUtils.getWindowWidth() / 2;
        ((FragmentGameBinding) this.binding).banner.setLayoutParams(layoutParams);
        ((FragmentGameBinding) this.binding).banner.setIndicator(new RectangleIndicator(getActivity()));
        ((FragmentGameBinding) this.binding).banner.setAdapter(new MyBannerAdapter(list, SpUtils.getInstance().getString("domain"), this));
        ((FragmentGameBinding) this.binding).banner.setOnBannerListener(new OnBannerListener() {
            /* class com.grass.p019lv.game.GameFragment.C30184 */

            @Override // com.youth.banner.listener.OnBannerListener
            public void OnBannerClick(Object obj, int i) {
                GameFragment.this.clickAd((AdInfoBean) obj);
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void clickAd(AdInfoBean adInfoBean) {
        if (!isOnClick() && adInfoBean != null) {
            if (adInfoBean.getJumpType() == 2) {
                try {
                    Intent intent = new Intent();
                    intent.setAction("android.intent.action.VIEW");
                    intent.setData(Uri.parse(adInfoBean.getAdJump()));
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                if (this.appLink == null) {
                    this.appLink = new APPLink(getActivity());
                }
                this.appLink.urlLink(adInfoBean.getAdJump());
            }
            Intent intent2 = new Intent(getActivity(), AdClickService.class);
            intent2.putExtra("adId", adInfoBean.getAdId());
            getActivity().startService(intent2);
        }
    }

    /* renamed from: com.grass.lv.game.GameFragment$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void gameCharge() {
            if (!GameFragment.this.isOnClick()) {
                GameFragment.this.startActivity(new Intent(GameFragment.this.getActivity(), GameRechargeActivity.class));
            }
        }

        public void gameWithdraw() {
            if (!GameFragment.this.isOnClick()) {
                GameFragment.this.startActivity(new Intent(GameFragment.this.getActivity(), GameWithdrawActivity.class));
            }
        }
    }
}
